package com.project.mall;

import com.project.mall.mapper.MapperC;
import com.project.mall.pojo.Address;
import com.project.mall.pojo.Orders;
import com.project.mall.pojo.Orderstate;
import com.project.mall.pojo.User;
import com.project.mall.service.ServiceC;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import javax.persistence.criteria.Order;
import java.util.Date;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class MallApplicationTestsc {
    @Resource
    private ServiceC mapper;
    @Test
    public void contextLoads() {
        String phone="13003945623";
        System.out.println(mapper.register(phone));
    }

    @Test
    public void testadduser() {
        User user = new User();
        user.setOthername("张三");
        user.setPassword("123456");
        user.setPhone("13003945623");
        System.out.println(mapper.addNewUser(user));
    }

  /*  @Test
    public void getalltest() {
        int userid=1;
        System.out.println(mapper.getAllbyID(userid).getOthername());
    }*/
/*
    @Test
    public void getIdByPhone() {
        String phone = "13003945623";
        System.out.println(mapper.getIdByPhointne(phone));
    }*/
    @Test
    public void updateuser() {
        User user = new User();
        user.setUserid(2);
        user.setOthername("张国荣");
        user.setPhone("13003945623");
        user.setSign("我的孤独是因为我既希望有人关心 又不想被谁过分打扰");
        user.setFavor("音乐，舞蹈");
        boolean kkk=mapper.updateUser(user);
        System.out.println(mapper.updateUser(user));
    }

    @Test
    public void updatepwd() {
        User user = new User();
        user.setPassword("123456");
        user.setPhone("13003945623");
        user.setUserid(2);
        System.out.println();
        boolean kkk=mapper.updatepwd(user);
        System.out.println(mapper.updatepwd(user));
    }

    @Test
    public void adress() {
        int userid =1;
      List<Address> kkk=mapper.getAdressByuser(userid);
      for (Address k:kkk){
          System.out.println(k.getAddress1()+k.getAddId());
      }

    }

    @Test
    public void adress2() {
        Address address = new Address();
        int userid =2;
        String address2 = "美国";
       address.setUserid(userid);
       address.setAddress1(address2);
            System.out.println(mapper.addAddress(address));

    }

    @Test
    public void updateAddress() {
        Address address = new Address();
        int addid1 =7;
        String address2 = "美国sdasda";
        String othername = "美国sdasda";
        String phone = "美国sdasda";
        address.setAddId(addid1);
        address.setAddress1(address2);
        address.setAddressPhone(phone);
        address.setAddressName(othername);
        System.out.println(mapper.updateAddress(address));

    }
    @Test
    public void getadd() {
        Address address = new Address();
        int addid =7;
        System.out.println(mapper.getaddressAllByAddID(addid).getAddress1());

    }


    @Test
    public void SeleorderByuserid() {
        int userid = 1;
        List<Orders> kk = mapper.getSelfrderby(userid);
        for (Orders kkk:kk){

            System.out.println(kkk.getOrderstate().getOrderstate());
        }


    }
    @Test
    public void addorders() {
        String ordercode ="123";
        int orderstateid=0;
        int gcolorid =12;
        int gtypeid =1;
        int gid =1;
        int ordercount =1;
        int userid =1;
        int reciveid =1;
        Orders order = new Orders();
        order.setOrderstateid(orderstateid);
        order.setGcolorid(gcolorid);
        order.setOrdercode(ordercode);
        order.setGtypeid(gtypeid);
        order.setGid(gid);
        order.setOrdercount(ordercount);
        order.setUserid(userid);
        order.setReciveid(reciveid);

        mapper.addorders(order);
        System.out.println(mapper.addorders(order));

    }

}
